# Contributor: Justin Berthault <justin.berthault@zaclys.net>
# Maintainer:
pkgname=writefreely
pkgver=0.15.1
pkgrel=0
pkgdesc="Federated blogging from write.as"
url="https://writefreely.org"
arch="all !riscv64" # riscv64 fails to build
license="AGPL-3.0-or-later"
pkgusers="$pkgname"
pkggroups="$pkgname"
makedepends="go go-bindata sqlite-dev npm"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/writefreely/writefreely/archive/v$pkgver.tar.gz
	package.json
	package-lock.json
	https://dev.alpinelinux.org/archive/writefreely/writefreely-0.15.0-openssl3.patch
	config.ini
	"
options="!check net"

export GOFLAGS="$GOFLAGS -modcacherw"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare

	cp "$srcdir"/package*.json .
	npm clean-install

	(
		cd cmd/writefreely
		go mod download -x
	)

	(
		cd prose
		npm clean-install --frozen-lockfile
	)
}

build() {
	PATH="$PWD/node_modules/.bin:$PATH" make -C less

	(
		cd prose
		npm run-script build
	)

	make build

	cd cmd/writefreely
	go build -v -tags=sqlite,libsqlite3
}

check() {
	make test
}

package() {
	install -d -o $pkgname -g $pkgname "$pkgdir"/var/lib/$pkgname
	install -d -o $pkgname -g $pkgname "$pkgdir"/var/lib/$pkgname/keys
	install -d -o $pkgname -g $pkgname "$pkgdir"/var/lib/$pkgname/data

	install -dm755 "$pkgdir"/usr/share/$pkgname/pages
	install -dm755 "$pkgdir"/usr/share/$pkgname/static
	install -dm755 "$pkgdir"/usr/share/$pkgname/templates

	install -Dm644 "$srcdir"/config.ini "$pkgdir"/etc/writefreely/config.ini

	install -Dm755 "$builddir"/cmd/$pkgname/$pkgname "$pkgdir"/usr/bin/$pkgname
	cp -r "$builddir"/pages/* "$pkgdir"/usr/share/writefreely/pages
	cp -r "$builddir"/static/* "$pkgdir"/usr/share/writefreely/static
	cp -r "$builddir"/templates/* "$pkgdir"/usr/share/writefreely/templates
}

sha512sums="
e4627bc514845d0cb2ea50b8cfca9db241b77f5e2bbfd0d3615bf14ef32065b95676f545b35ad4807057c5264ea1ae1969e52be9e28cd933b4edfdb74f9d64e9  writefreely-0.15.1.tar.gz
56aa3017b34a11b77a318772d2e34645a017e2ac66e75205dac31d4d6f2c7da48a6ced7ec8050babe258c7719151b79c9bb668f1fa6243f09fd1268d4eefc602  package.json
73562b98a69fe34bb8d976922db37ec7d722f0f599572221dba1dfd9d896d776ab6a3eaeb91b03e4ed081ceea97b8ec60fbe9b9c1e960dc9810506b8fde3500d  package-lock.json
b30e0cabf84677ab521891f71676e274b4f13597cf868e166e26810f1a4005331c9f0af8a1b9b8cd804540437196b2d5d03b3b1d275854c9a0a0e7141e12ec1a  writefreely-0.15.0-openssl3.patch
27685562af68e5c03850cf346e95f87657dfceffc396441ca3315ca2065ccd4ea86dbd831b0c3f1dce99de4a6317eaf495ce979d5e98c3feeebbd0fbc793fa30  config.ini
"
